package com.sqlSession;

import com.config.XMLConfigBuilder;
import com.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * Created with IDEA by ChouFy on 2020/2/20.
 *
 * @author Zhoufy
 */
public class SqlSessionFactoryBuilder {


    public SqlSessionFactory build(InputStream input) throws DocumentException, PropertyVetoException {
        //第一: 使用dom4j 解析配置文件，将解析出来的内容封装到Configuration中

        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.paresConfig(input);


        //第二: 创建sqlSessionFactory对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
